/**
 * 
 */
package com.edocbase.biz.nodes;

import java.util.HashMap;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.swt.graphics.Image;

/**
 * @author X61
 *
 */
public class MultiLabelProvider extends LabelProvider {
	private HashMap<Class<?>, LabelProvider> providerMap = new HashMap<Class<?>, LabelProvider>();

	public void registProvider(Class<?> clzKey,LabelProvider labelProvider){
		providerMap.put(clzKey, labelProvider);
	}
	
	@Override
	public Image getImage(Object element) {
		Class<?> clzKey = element.getClass();
		if (providerMap.containsKey(clzKey)){
			LabelProvider label = providerMap.get(clzKey);
			return label.getImage(element);
		}else if (element instanceof TreeNode){
			TreeNode node = (TreeNode)element;
			Object obj = node.getValue();
			clzKey = obj.getClass();
			if (providerMap.containsKey(clzKey)){
				LabelProvider label = providerMap.get(clzKey);
				return label.getImage(obj);
			}
		}
		return null;
	}

	@Override
	public String getText(Object element) {
		Class<?> clzKey = element.getClass();
		if (providerMap.containsKey(clzKey)){
			LabelProvider label = providerMap.get(clzKey);
			return label.getText(element);
		}else if (element instanceof TreeNode){
			TreeNode node = (TreeNode)element;
			Object obj = node.getValue();
			clzKey = obj.getClass();
			if (providerMap.containsKey(clzKey)){
				LabelProvider label = providerMap.get(clzKey);
				return label.getText(obj);
			}else{
				return node.getValue().toString();
			}
		}
		return super.getText(element);
	}
	
	
}
